<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

    <script>

        // 练习---字符串的压缩统计
        var str = 'goodgoodgoo' ;
        // g3o6d2

        // 1 先去重   god
        var str2 = '' ;

        // 遍历原字符串
        for(let i in str) {
            // 判断str[i]再新数组中是否存在
            if(str2.includes(str[i])) {
                continue ;
            } 
            str2 += str[i] ;
            

            // if(str2.includes(str[i]) === false) {
            //     str2 += str[i]
            // }

            // if(!str2.includes(str[i])) {
            //     str2 += str[i]
            // }
        }

        console.log(str2);


        var res = '';
        // god
        for(var i in str2) {
            var count = 0 ;
            for(var j in str) {
                if(str2[i] === str[j]) {
                    count++ ;
                }
            }
            // console.log(str2[i] + '出现了' + count + '次');
            res += str2[i] + count ;
        }

        console.log(res);
    </script>
    
</body>
</html>